home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
clonecd
/
September 93.img
/
Archives
/
Decoration
/
Screensavers
/
Screen Savers
/
TwilightZone
/
source
/
aevt.c
next >
Wrap
Text File
|
1993-06-14
|
4KB
|
187 lines
/*-------------------------------------------------------------------------------------
*
* Simple Sample Application Framework
*
* ©1991 Apple Computer
*
-------------------------------------------------------------------------------------*/
/*
* aevt.c -- appleevents code
*
* change history:
*
* SJF 11/6/91 1.0d1 initial coding
*
*/
#include <Types.h>
#include <Menus.h>
#include <Traps.h>
#include <GestaltEqu.h>
#include <AppleEvents.h>
#include "const.h"
#include "trapAvailable.h"
#include "events.h"
#include "globals.h"
#include "utils.h"
#include "aevt.h"
Boolean SupportsAEVT(void)
{
OSErr err;
long response;
if (!TrapAvailable(_Gestalt))
return false;
err = Gestalt(gestaltAppleEventsAttr,&response);
if (err!=noErr)
return false;
return (response && (response << gestaltAppleEventsPresent));
}
void DoHighLevelEvent(EventRecord *ev)
{
OSErr err;
err = AEProcessAppleEvent(ev);
if (err!=noErr)
DoError(err);
}
void RegisterMyEvents(void)
{
OSErr err;
if (!SupportsAEVT())
return;
err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,(ProcPtr)&MyAEHandleOAPP,0L,false);
if (err!=noErr)
return;
err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,(ProcPtr)&MyAEHandleODOC,0L,false);
if (err!=noErr)
return;
err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,(ProcPtr)&MyAEHandlePDOC,0L,false);
if (err!=noErr)
return;
err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,(ProcPtr)&MyAEHandleQUIT,0L,false);
if (err!=noErr)
return;
}
pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
{
OSErr err;
err = MyGotRequiredParams(theAppleEvent);
if (err!=noErr)
return err;
}
pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
{
FSSpec myFSS;
AEDescList docList;
OSErr err;
long index,itemsInList;
Size actualSize;
AEKeyword keywd;
DescType returnedType;
err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
if (err!=noErr)
return err;
err = MyGotRequiredParams(theAppleEvent);
if (err!=noErr)
return err;
err = AECountItems(&docList,&itemsInList);
for (index=1; index<=itemsInList; index++) {
err = AEGetNthPtr(&docList,index,typeFSS,&keywd,&returnedType,(Ptr)&myFSS,
sizeof(myFSS),&actualSize);
if (err!=noErr)
return err;
err = HandleOpenDoc(&myFSS);
if (err!=noErr)
return err;
}
err = AEDisposeDesc(&docList);
return noErr;
}
pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
{
FSSpec myFSS;
AEDescList docList;
OSErr err;
long index,itemsInList;
Size actualSize;
AEKeyword keywd;
DescType returnedType;
err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
if (err!=noErr)
return err;
err = MyGotRequiredParams(theAppleEvent);
if (err!=noErr)
return err;
err = AECountItems(&docList,&itemsInList);
for (index=1; index<=itemsInList; index++) {
err = AEGetNthPtr(&docList,index,typeFSS,&keywd,&returnedType,(Ptr)&myFSS,
sizeof(myFSS),&actualSize);
if (err!=noErr)
return err;
err = HandlePrintDoc(&myFSS);
if (err!=noErr)
return err;
}
err = AEDisposeDesc(&docList);
return noErr;
}
pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
{
OSErr err;
err = MyGotRequiredParams(theAppleEvent);
if (err!=noErr)
return err;
gDone = true;
}
OSErr MyGotRequiredParams(AppleEvent *theAppleEvent)
{
DescType returnedType;
Size actualSize;
OSErr err;
err = AEGetAttributePtr(theAppleEvent,keyMissedKeywordAttr,typeWildCard,
&returnedType,nil,0,&actualSize);
if (err == errAEDescNotFound)
err = noErr;
else if (err==noErr)
err = errAEEventNotHandled;
return err;
}